package tech.aistar.corejava.day16;

import java.io.File;
import java.io.FilenameFilter;

/**
 * @author success
 * @version 1.0
 * @description:本类用来演示:
 * @date 2019/8/5 0005
 */
public class FileSuffixFilter implements FilenameFilter{
    private String suffix;

    public FileSuffixFilter(String suffix){
        this.suffix = suffix;
    }

    @Override
    public boolean accept(File dir, String name) {
        //File f = new File("d:/temp/abc.txt"); -> File ff = new File("d:/temp","abc.txt");

        File file = new File(dir,name);
        //System.out.println(file);

        //System.out.println("accept:"+dir+":"+name);
        if(file.isDirectory()){//只有进去之后才能找文件 - 如果false,那么这个目录不会遍历
            return true;
        } else if(name.endsWith(suffix)){
            return true;
        }
        return false;
    }
}
